package com.tfswx.jcyw.ruleenginedesigner.api;

import com.tfswx.jcyw.ruleenginedesigner.bean.ApiResult;
import com.tfswx.jcyw.ruleenginedesigner.dto.stgl.*;
import com.tfswx.jcyw.ruleenginedesigner.service.StglService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.NonNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Ricky
 * @date 2021/5/11
 */
@RestController
@RequestMapping("/stgl")
@Api(tags = "实体管理")
public class StglController {

    @Resource
    private StglService stglService;

    @ApiOperation("根据项目编码获取实体定义列表")
    @PostMapping("/queryStdyListByXmbm")
    public ApiResult<List<StdyListByXmbmQueryOutputDTO>> queryStdyListByXmbm(@NonNull @RequestBody @Validated StdyListByXmbmQueryInputDTO stdyListByXmbmQueryInputDTO) {
        List<StdyListByXmbmQueryOutputDTO> stdyList = stglService.queryStdyListByXmbm(stdyListByXmbmQueryInputDTO);
        return ApiResult.success(stdyList);
    }

    @ApiOperation("添加实体定义")
    @PostMapping("/addStdy")
    public ApiResult<String> addStdy(@NonNull @RequestBody @Validated StdyAddInputDTO stdyAddInputDTO) {
        String stdybm = stglService.addStdy(stdyAddInputDTO);
        return ApiResult.success(stdybm);
    }

    @ApiOperation("修改实体定义")
    @PostMapping("/updateStdy")
    public ApiResult<Boolean> updateStdy(@NonNull @RequestBody @Validated StdyUpdateInputDTO stdyUpdateInputDTO) {
        boolean isSucc = stglService.updateStdy(stdyUpdateInputDTO);
        return ApiResult.success(isSucc);
    }

    @ApiOperation("删除实体定义")
    @PostMapping("/deleteStdy")
    public ApiResult<Boolean> deleteStdy(@NonNull @RequestBody @Validated StdyDeleteInputDTO stdyDeleteInputDTO) {
        boolean isSucc = stglService.deleteStdy(stdyDeleteInputDTO);
        return ApiResult.success(isSucc);
    }

    @ApiOperation("根据实体编码获取实体结构列表")
    @PostMapping("/queryStjgListByStbm")
    public ApiResult<List<StjgListByStdybmQueryOutputDTO>> queryStjgListByStdybm(@NonNull @RequestBody @Validated StjgListByStdybmQueryInputDTO stjgListByStdybmQueryInputDTO) {
        List<StjgListByStdybmQueryOutputDTO> stjgList = stglService.queryStjgListByStdybm(stjgListByStdybmQueryInputDTO);
        return ApiResult.success(stjgList);
    }

    @ApiOperation("添加实体结构")
    @PostMapping("/addStjg")
    public ApiResult<String> addStjg(@NonNull @RequestBody @Validated StjgAddInputDTO stjgAddInputDTO) {
        String stjgbm = stglService.addStjg(stjgAddInputDTO);
        return ApiResult.success(stjgbm);
    }

    @ApiOperation("修改实体结构")
    @PostMapping("/updateStjg")
    public ApiResult<Boolean> updateStjg(@NonNull @RequestBody @Validated StjgUpdateInputDTO stjgUpdateInputDTO) {
        boolean isSucc = stglService.updateStjg(stjgUpdateInputDTO);
        return ApiResult.success(isSucc);
    }

    @ApiOperation("删除实体结构")
    @PostMapping("/deleteStjg")
    public ApiResult<Boolean> deleteStjg(@NonNull @RequestBody @Validated StjgDeleteInputDTO stjgDeleteInputDTO) {
        boolean isSucc = stglService.deleteStjg(stjgDeleteInputDTO);
        return ApiResult.success(isSucc);
    }

    @ApiOperation("获取实体树")
    @PostMapping("/queryStTree")
    public ApiResult<List<StTreeQueryOutputDTO>> queryStTree(@NonNull @RequestBody @Validated StTreeQueryInputDTO stTreeQueryInputDTO) {
        List<StTreeQueryOutputDTO> stTree = stglService.queryStTree(stTreeQueryInputDTO);
        return ApiResult.success(stTree);
    }

}
